<template>
  <basic-container>
    <avue-crud :option="option"
               :data="data"
               ref="crud"
               v-model="form"
               :table-loading="loading"
               :permission="permissionList"
               @row-del="rowDel"
               @row-update="rowUpdate"
               @row-save="rowSave"
               :page="page"
               @refresh-change="refreshChange"
               @search-change="searchChange"
               @search-reset="searchReset"
               @current-change="currentChange"
               @size-change="sizeChange"
               @on-load="onLoad">
    </avue-crud>
  </basic-container>
</template>

<script>
import {
  getList,
  remove,
  update,
  add
} from "@/api/base/store/storeDetail";
import { mapGetters } from "vuex";

export default {
  data () {
    return {
      form: {},
      query: {},
      loading: true,
      rolesTree: [],
      rolesKeys: [],
      box: false,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      option: {
        size: 'mini',
        excelBtn: true,
        tip: false,
        border: true,
        index: true,
        selection: true,
        viewBtn: true,
        rowKey: 'id',
        height: 'auto',
        // calcHeight: 380,
        dialogType: 'dialog',
        menuWidth: 300,
        column: [
          {
            label: "身份认证  0:否  1:是",
            prop: "cardApprove",
            fixed: true,
            rules: [{
              required: true,
              message: "请输入身份认证  0:否  1:是",
              trigger: "blur"
            }]
          },
          {
            label: "营业执照认证  0:否  1:是",
            prop: "realstoreApprove",
            rules: [{
              required: true,
              message: "请输入营业执照认证  0:否  1:是",
              trigger: "blur"
            }]
          },
          {
            label: "店铺地址",
            prop: "storeAddress",
            rules: [{
              required: true,
              message: "请输入店铺地址",
              trigger: "blur"
            }]
          },
          {
            label: "店铺信用分",
            prop: "storeCredit",
            rules: [{
              required: true,
              message: "请输入店铺信用分",
              trigger: "blur"
            }]
          },
          {
            label: "店铺联系人电话",
            prop: "storeTelephone",
            rules: [{
              required: true,
              message: "请输入店铺联系人电话",
              trigger: "blur"
            }]
          },
          {
            label: "审核原因",
            prop: "violationReseaon",
            rules: [{
              required: true,
              message: "请输入审核原因",
              trigger: "blur"
            }]
          },
          {
            label: "店铺二级域名",
            prop: "storeSecondDomain",
            rules: [{
              required: true,
              message: "请输入店铺二级域名",
              trigger: "blur"
            }]
          },
          {
            label: "收藏次数",
            prop: "favoriteCount",
            rules: [{
              required: true,
              message: "请输入收藏次数",
              trigger: "blur"
            }]
          },
          {
            label: "店铺坐标",
            prop: "storeLat",
            rules: [{
              required: true,
              message: "请输入店铺坐标",
              trigger: "blur"
            }]
          },
          {
            label: "店铺坐标",
            prop: "storeLng",
            rules: [{
              required: true,
              message: "请输入店铺坐标",
              trigger: "blur"
            }]
          },
          {
            label: "地图类型   例如baidu、gaode",
            prop: "mapType",
            rules: [{
              required: true,
              message: "请输入地图类型   例如baidu、gaode",
              trigger: "blur"
            }]
          },
          {
            label: "二维码",
            prop: "weixinQrImgUrl",
            rules: [{
              required: true,
              message: "请输入二维码",
              trigger: "blur"
            }]
          },
          {
            label: "统一社会信用代码",
            prop: "taxNo",
            rules: [{
              required: true,
              message: "请输入统一社会信用代码",
              trigger: "blur"
            }]
          },
          {
            label: "",
            prop: "goodsClassId",
            rules: [{
              required: true,
              message: "请输入",
              trigger: "blur"
            }]
          },
          {
            label: "公司名称",
            prop: "companyName",
            rules: [{
              required: true,
              message: "请输入公司名称",
              trigger: "blur"
            }]
          },
          {
            label: "公司邮箱",
            prop: "storeEmail",
            rules: [{
              required: true,
              message: "请输入公司邮箱",
              trigger: "blur"
            }]
          },
          {
            label: "店主生日",
            prop: "storeOwnerBirthday",
            rules: [{
              required: true,
              message: "请输入店主生日",
              trigger: "blur"
            }]
          },
          {
            label: "店主邮箱",
            prop: "storeOwnerEmail",
            rules: [{
              required: true,
              message: "请输入店主邮箱",
              trigger: "blur"
            }]
          },
          {
            label: "店主电话",
            prop: "storeOwnerTel1",
            rules: [{
              required: true,
              message: "请输入店主电话",
              trigger: "blur"
            }]
          },
          {
            label: "店主身份证",
            prop: "storeOwnerTel2",
            rules: [{
              required: true,
              message: "请输入店主身份证",
              trigger: "blur"
            }]
          },
          {
            label: "店铺所有者性别(1:女;2:男)",
            prop: "storeOwnerSex",
            rules: [{
              required: true,
              message: "请输入店铺所有者性别(1:女;2:男)",
              trigger: "blur"
            }]
          },
          {
            label: "发货类型  默认都是1",
            prop: "shipType",
            rules: [{
              required: true,
              message: "请输入发货类型  默认都是1",
              trigger: "blur"
            }]
          },
          {
            label: "营业执照号",
            prop: "businessNo",
			display:false,
            rules: [{
              required: true,
              message: "请输入营业执照号",
              trigger: "blur"
            }]
          },
          {
            label: "营业执照起始时间",
            prop: "storeCredentialsStarttime",
			display:false,
            rules: [{
              required: true,
              message: "请输入营业执照起始时间",
              trigger: "blur"
            }]
          },
          {
            label: "营业执照结束时间",
            prop: "storeCredentialsEndtime",
			display:false,
            rules: [{
              required: true,
              message: "请输入营业执照结束时间",
              trigger: "blur"
            }]
          },
          {
            label: "店铺注册类型 1:PC注册,2：安卓,3:IOS, 4:H5",
            prop: "registerType",
            rules: [{
              required: true,
              message: "请输入店铺注册类型 1:PC注册,2：安卓,3:IOS, 4:H5",
              trigger: "blur"
            }]
          },
          {
            label: "营业期限",
            prop: "businessTerm",
            rules: [{
              required: true,
              message: "请输入营业期限",
              trigger: "blur"
            }]
          },
          {
            label: "店铺id",
            prop: "storeId",
            rules: [{
              required: true,
              message: "请输入店铺id",
              trigger: "blur"
            }]
          },
          {
            label: "银行id对应base_bank中的id",
            prop: "bankId",
            rules: [{
              required: true,
              message: "请输入银行id对应base_bank中的id",
              trigger: "blur"
            }]
          },
          {
            label: "银行账户持有人姓名",
            prop: "accountName",
            rules: [{
              required: true,
              message: "请输入银行账户持有人姓名",
              trigger: "blur"
            }]
          },
          {
            label: "银行账户号码",
            prop: "accountNum",
            rules: [{
              required: true,
              message: "请输入银行账户号码",
              trigger: "blur"
            }]
          },
          {
            label: "银行地址市级id",
            prop: "accountAddressId",
            rules: [{
              required: true,
              message: "请输入银行地址市级id",
              trigger: "blur"
            }]
          },
          {
            label: "持卡人手机号",
            prop: "accountMobile",
            rules: [{
              required: true,
              message: "请输入持卡人手机号",
              trigger: "blur"
            }]
          },
          {
            label: "持卡人身份证号",
            prop: "accountIdNum",
            rules: [{
              required: true,
              message: "请输入持卡人身份证号",
              trigger: "blur"
            }]
          }
        ]
      },
      data: []
    };
  },
  computed: {
    ...mapGetters(["permission", 'userInfo']),
    permissionList () {
      return {
        addBtn: this.vaildData(this.permission["/mall-cloud-base/storeDetail/addItem"], false),
        viewBtn: this.vaildData(this.permission["/mall-cloud-base/storeDetail/detail"], false),
        delBtn: this.vaildData(this.permission["/mall-cloud-base/storeDetail/delete"], false),
        editBtn: this.vaildData(this.permission["/mall-cloud-base/storeDetail/editItem"], false)
      };
    },
  },
  methods: {
    rowSave (row, loading, done) {
      row.position = row.positionIds;
      row.deptName = row.$deptId;
      row.repassword = row.password;
      add(row).then(() => {
        loading();
        this.onLoad(this.page);
        this.$message({
          type: "success",
          message: "操作成功!"
        });
      }, error => {
        done();
        ;
      });
    },
    rowUpdate (row, index, loading, done) {
      row.position = row.positionIds;
      update(row).then(() => {
        loading();
        this.onLoad(this.page);
        this.$message({
          type: "success",
          message: "操作成功!"
        });
      }, error => {
        done();
        ;
      });
    },
    rowDel (row) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          return remove(row.id);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
        });
    },
    searchReset () {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange (params,done) {
      this.query = params;
      this.onLoad(this.page, params,done);
    },
    currentChange (currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange (pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange () {
      this.onLoad(this.page);
    },
    onLoad (page, params = {},done) {
      this.loading = true;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
        if(done){
          done();
        }
        this.loading = false;
        const data = res.data;
        this.page.total = data.count;
        this.data = data.data;
      });
    }
  }
};
</script>

<style>
</style>
